package com.sky.mapper;

import com.sky.model.entity.UserBehavior;
import com.sky.model.vo.Top10ReportVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


@Mapper
public interface UserBehaviorMapper {
    /**
     * 添加收藏A
     * @param userBehavior
     */
    @Insert("insert userbehavior (userId, shopId) values(#{userId}, #{shopId})")
    void insertBookmark(UserBehavior userBehavior);

    /**
     * 删除收藏A
     * @param userBehavior
     */
    @Delete("delete from userbehavior where userId = #{userId} and shopId = #{shopId}")
    void removeBookmark(UserBehavior userBehavior);

    /**
     * 添加/删除收藏B
     * @param
     */
    @Update("update userbehavior set bookmark = #{bookmark} where userId = #{userId} and shopId = #{shopId}")
    void updateBookmark(int bookmark, Long userId, Long shopId);

    /**
     * 查询收藏，判断是否已经收藏或浏览
     * @param userId
     * @param shopId
     */
    @Select("select * from userbehavior ub where ub.userId  = #{userId} and  ub.shopId = #{shopId}")
    UserBehavior userBehavior(Long userId, Long shopId);

    /**
     * 添加浏览量A
     * @param userBehavior
     */
    @Insert("insert userbehavior (userId, shopId, views) values(#{userId}, #{shopId}, #{views})")
    void addViews(UserBehavior userBehavior);

    /**
     * 添加浏览量B
     * @param userBehavior
     */
    @Update("update userbehavior set views = #{views} where userId = #{userId} and shopId = #{shopId}")
    void updateViews(UserBehavior userBehavior);

    /**
     * 根据时间查询流量
     * @param map
     */

    Integer countViewByMap(Map map);

    /**
     * 查询TOP10流量
     *
     * @param map
     */
    List<Top10ReportVO> selectTop10Views(Map<String, Object> map);
}
